<?php

namespace App;

use App\model\WechatUser;
use Illuminate\Database\Eloquent\Model;

/**
 * App\WechatLink
 *
 * @property int $id
 * @property string|null $url
 * @property string|null $name
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\model\WechatUser[] $user
 * @property-read int|null $user_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink whereUrl($value)
 * @mixin \Eloquent
 * @property string|null $wechat_link_id 微信获客id
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink whereWechatLinkId($value)
 * @property string|null $user_ids
 * @method static \Illuminate\Database\Eloquent\Builder|\App\WechatLink whereUserIds($value)
 */
class WechatLink extends Model
{
    protected $table='wechat_link';
    public function user(){
        return $this->belongsToMany(WechatUser::class,'wechat_link_user','link_id','userid','id','userid');
    }
    public function getUserIdsAttribute($value)
    {
        return explode(',', $value);
    }

    public function setUserIdsAttribute($value)
    {
        $this->attributes['user_ids'] = implode(',', $value);
    }
}
